﻿
using System;
using System.Collections.Generic;

namespace GECS.MapEngine {

	/// <summary>
	/// A manager to control the order of maps to be loaded. Has the flexibility to
	/// add new maps and to load a null map. Can also be used to go to previous map
	/// or next map.
	/// </summary>
    public class MapManager {

		private static List<MapInfo> maps = new List<MapInfo>();
		
		/// <summary>
		/// The ID of the Current Map
		/// </summary>
		public static int CurrentMap = 0;
		
		/// <summary>
		/// Adds a new map next to the current map.
		/// </summary>
		/// <param name="info">The MapInfo object containing the information about the map.</param>
		public static void AddMap(MapInfo info){
			maps.Add(info);
		}
		
		/// <summary>
		/// Goes to the first map.
		/// </summary>
		public static void StartFirstMap(){
			CurrentMap = 0;
			ReloadMap();
		}
		
		/// <summary>
		/// Returns true if there is another map in order.
		/// </summary>
		/// <returns>Whether a map is present to be loaded next.</returns>
		public static bool HasNextMap(){
			if (maps.Count > CurrentMap + 1){
				return true;
			}
			return false;
		}
		
		/// <summary>
		/// Returns true if a map exists before this map.
		/// </summary>
		/// <returns>Whether a map is present to be loaded before.</returns>
		public static bool HasPreviousMap(){
			if (CurrentMap > 0){
				return true;
			}
			return false;
		}
		
		/// <summary>
		/// Loads the next map in the order.
		/// </summary>
		public static void LoadNextMap(){
			if (HasNextMap()){
				CurrentMap++;
				Map.LoadMap(maps[CurrentMap]);
			}
		}
		
		/// <summary>
		/// Loads the previous map in the order.
		/// </summary>
		public static void LoadPreviousMap(){
			if (HasPreviousMap()){
				CurrentMap--;
				Map.LoadMap(maps[CurrentMap]);
			}
		}
		
		/// <summary>
		/// Reloads the current map.
		/// </summary>
		public static void ReloadMap(){
			Map.LoadMap(maps[CurrentMap]);
		}
		
		/// <summary>
		/// Loads a null map. Equivalent to calling Map.clearObjects().
		/// </summary>
		public static void LoadNullMap(){
			Map.ClearObjects();
		}
		
		/// <summary>
		/// Loads a map with a specified index.
		/// </summary>
		/// <param name="mapnum">The number of map in order.</param>
		public static void LoadMap(int mapnum){
			Map.LoadMap(maps[mapnum]);
		}

    }

}
